package com.example.figurehecheng.controller.merchant;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.figurehecheng.common.result.Result;
import com.example.figurehecheng.domain.dto.CommentDTO;
import com.example.figurehecheng.domain.entity.Comment;
import com.example.figurehecheng.service.ICommentService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 宇科工作室
 * @since 2024-10-18
 */
@RestController("merchantCommentController")
@CrossOrigin
@RequestMapping("/merchant/comment")
@RequiredArgsConstructor
public class CommentController {

    private final ICommentService iCommentService;

    /**
     * 获取所有评论和分数
     */
    @GetMapping("/getComment")
    @ApiOperation("获取所有评论和分数")
    public Result<List> getComment(){
     return Result.success(iCommentService.getComment());
    }

    /**
     * 商家回复评论
     * @param commentDTO
     */
    @PostMapping("/sureComment")
    @ApiOperation("商家回复评论")
    public void sureComment(@RequestBody CommentDTO commentDTO){
        iCommentService.sureComment(commentDTO);
    }

    @DeleteMapping("/deleteComment")
    @ApiOperation("商家删除评论")
    public Result deleteComment(@RequestParam(value = "id") Integer id,
                              @RequestParam(value = "pid") Integer pid){
        iCommentService.remove(new QueryWrapper<Comment>()
                        .lambda().eq(Comment::getId,id)
                .eq(Comment::getPid,pid));
      return  Result.success();
    }

}
